package workexp.alg.question.linklist;

import workexp.alg.env.ListNode;

public class HasCycle {
    public boolean hasCycle(ListNode head) {
        ListNode fast,slow;
        if(head==null){
            return false;
        }
        slow=head;
        fast=head.next;

        while(fast!=null&&fast.next!=null){
            if(fast==slow){
                return true;
            }
            if(fast.next.next==null){
                return false;
            }
            fast=fast.next.next;
            slow=slow.next;
        }
        return false;

    }
}
